<template>
	<view>
		<initlate :leaders="leader" :participant="participants" :page="false" :taskId="id" @refresh="refresh" @peopleclose="peopleChange"></initlate>
	</view>
</template>

<script>
	import initlate from '../component/initlate/initlate';
	export default {
		components:{
			initlate
		},
		data() {
			return {
				id:null,
				leader:[],
				participants:[],
			}
		},
		onLoad(option) {
			this.id = option.id;
			getApp().globalData.personList = {leader:[],participants:[],assignment:[]};
		},
		onShow() {
			let personList = getApp().globalData.personList;
			console.log('assignment',personList.assignment);
			let arr = [];
			if(personList.assignment.id){
				arr.push(personList.assignment);
			}
			this.leader = arr;
			this.participants = personList.participants;
			console.log('leader',this.leader);
		},
		onUnload(){
			
			getApp().globalData.personList = {leader:[],participants:[],assignment:[]};
		},
		
		methods: {
			refresh:function(){
				getApp().globalData.selected = 3;
				uni.navigateBack();
			},
			peopleChange:function(e){
				console.log('close',e);
				if(e.key == 'leader'){
					this.leaderCloseChange(e.index);
				}else if(e.key == 'participant'){
					this.participantsCloseChange(e.index);
				}
			},
			/**
			 * 负责人关闭按钮点击触发事件
			 */
			leaderCloseChange:function(e){
				let personList = getApp().globalData.personList;
				personList.leader.splice(e, 1);
				getApp().globalData.personList = personList;
				this.leader = personList.leader;
			},
			/**
			 * 参与人关闭按钮点击触发事件
			 */
			participantsCloseChange:function(e){
				let personList = getApp().globalData.personList;
				personList.participants.splice(e, 1);
				getApp().globalData.personList = personList;
				this.participants = personList.participants;
			},
		}
	}
</script>

<style>

</style>
